package com.szxy.stream;

import com.szxy.bean.Employee;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author:zwer
 * @Date:2020/4/16 13:27
 * @Description:com.szxy.stream
 * @Version:1.0
 * 终结操作
 **/
public class TestLastStream {


    @Test
    public void test1() {
        List<Employee> list =  new ArrayList<>();
        list.add(new Employee(1, "张三", 10000));
        list.add(new Employee(2, "李四", 9000));
        list.add(new Employee(1, "张三", 10000));
        list.add(new Employee(4, "王五", 2000));

        Optional<Employee> max = list.stream().distinct().max(Comparator.comparingDouble(Employee::getSalary));
        System.out.println("max.get() = " + max.get());

        Optional<Employee> min = list.stream().distinct().min(Comparator.comparingDouble(Employee::getSalary));
        System.out.println("min.get() = " + min.get());

        boolean flag = list.stream()
                .filter(elm -> elm.getSalary() > 1000)
                .anyMatch(elm -> elm.getSalary() > 8000);
        System.out.println("flag = " + flag);

        List<Employee> collect = list.stream().distinct().collect(Collectors.toList());
        collect.forEach(System.out::println);

        list.stream().distinct().collect(Collectors.toSet()).forEach(System.out::println);

    }
}
